				#####################################
				# REPLICATION MATERIAL for: 
				# Di Leo, R., and Giani, M. (2023), Does Schooling Increase Political Belief Accuracy?
				#####################################


/*
*** Note: replicators should add to the local ado folder (identify it using the command "sysdir"): 

ado files to include in the Stata "ado" directory: 	"DCdensity.ado" "rddisttestk.ado"  	
(typically following a path "ado/plus/initial of the package", use command "sysdir" to identify it. Note that Stata must be restarted to incorporate the files change)	


	a. "DCdensity.ado" used to compute the density test (also available here: https://eml.berkeley.edu/~jmccrary/DCdensity/) 
		Developed by Justin McCrary. 
		See: McCrary, Justin. "Manipulation of the running variable in the regression discontinuity design: A density test." Journal of econometrics 142.2 (2008): 698-714.

	b. "rddisttestk.ado" used to compute the density test (also available here: https://economics.byu.edu/frandsen/Pages/Software.aspx) 
		Developed by Brigham R. Fradsen.
*/



/*
*** Note: replicators must install the following packages (by uncommenting this section)

ssc install eurostatuse, replace 

ssc install ebalance, replace
ssc install center, replace
ssc install estout, replace
ssc install grstyle, replace
ssc install coefplot, replace
ssc install rddsga, replace
ssc install kountry, replace
ssc install iscogen, replace 
ssc install rangestat, replace
ssc install rangejoin, replace 
ssc install nearmrg, replace

ssc install palettes
ssc install colrspace
*/



/*  
***Note on eurostatuse: 

	Developed by:  Sébastien Fontenay & Sem Vandekerckhove, 2015. "EUROSTATUSE: Stata module to import data from Eurostat repository into Stata," Statistical Software Components S458088, Boston College Department of Economics, revised 30 Sep 2018. 
	
	Online: https://ideas.repec.org/c/boc/bocode/s458088.html
	
	ssc install eurostatuse, replace 
	
	Data on Unemployment comes from: 
	*Unemployment by sex and age (1992-2020) - annual data
	*clear all 
	*eurostatuse une_rt_a_h, long label noflags
	*save "ESS\Unemp_raw", replace 
	
	Data on the share of Foreigners comes from:
	*Population on 1 January by age, sex and broad group of citizenship (1998-2021) - annual data
	*clear all
	*eurostatuse migr_pop2ctz, long label noflags
	*save "ESS\Foreign_raw", replace
*/



/*
***Note on ParlGov: 

	Source: Döring, Holger, Alexandra Quaas, Maike Hesse, and Philip Manow. 2023. Parliaments and governments database (ParlGov): Information on parties, elections and cabinets in established democracies. Development version.

	Online: https://www.parlgov.org/data-info/
	
	To determine the election dates and cabinets in charge we used the dataset and merged it with ESS data using the command "nearmrg": "view_cabinet.xls" 
*/



clear all
set graphics off


***Note: replicators should set up directories to open data and save tables and figures 
cd ""

glo Main "Main"

glo Appendix "Appendix"




/*FULL ESS DATASET (Appended 1-10 and cleaned)

use "ESS_clean_new.dta" , clear

keep Eduyears Age Male  Child Domicile Immigrant Unemployed Income Education_dad Edu_dad_dummy Edu_mum_dummy Interest Turnout Parliament Ideology Migrantsqualityoflife Unemplazy intdate noimbro uemplwk essround country cntry yrbrn regiongb livecnta brncntr intyear govt_int_left_right elec_int_start_date Foreign Unemp2

save "ESS_merged_replication.dta" , replace
erase "ESS_clean_new.dta"
*/



use "ESS_merged_replication.dta" , clear



	
####################################
############DATA CLEAN  ############
####################################

*noimbro : wave 1 and 7 
*uemplwk: wave 4 and 8

### 0. Generate outcome (belief accuracy)
g Guess_foreign=abs(noimbro-Foreign) if noimbro!=.
la var Guess_foreign "Distance between foreigners guess and sh. foreigners over tot. citizens (in interview year)"

g Guess_unemployment=abs(uemplwk-Unemp2) if uemplwk!=.
la var Guess_unemployment "Distance between Unemployment guess and Unemployment Rate (in interview year)"



#### 1. Generate guess without absolute value 
g Guess_foreign2=noimbro-Foreign
g Guess_unemployment2=uemplwk-Unemp2

replace Guess_foreign=-Guess_foreign
replace Guess_unemployment=-Guess_unemployment

label variable Guess_foreign "|Belief - Real|"
label variable Guess_foreign2 "Belief - Real"

label variable Guess_unemployment "|Belief - Real|"
label variable Guess_unemployment2 "Belief - Real"



#### 2. Distance closest election date before interview-interview )

g distance_date= intdate-elec_int_start_date


 
#### 3. Generate wave and country FEs

tabulate essround, generate(r)
tabulate country, generate(c)
encode cntry, g(Country)

 
 
#####  4. Right wing government at interview 
gen rightwing=. 
replace rightwing=0 if govt_int_left_right<=4.99
replace rightwing=1  if govt_int_left_right>=5.01



#### 5. Generate indicators to analyse non-answer to each type of question

*Foreigners
g Noanswer=.
replace Noanswer=0 if essround==1 & noimbro!=.
replace Noanswer=0 if essround==7 & noimbro!=. 
replace Noanswer=1 if noimbro==. & essround==1 
replace Noanswer=1 if noimbro==. & essround==7

*Unemployed
g Noanswer2=.
replace Noanswer2=0 if essround==4 & uemplwk!=.
replace Noanswer2=0 if essround==8 & uemplwk!=. 
replace Noanswer2=1 if uemplwk==. & essround==4
replace Noanswer2=1 if uemplwk==. & essround==8



#### 6. Education years 

g eduyrs=Eduyears

* Recode the education variable to cap at 13 years 
g total_eduyrs = eduyrs
label var total_eduyrs "Years of education (total)"
replace eduyrs = 13 if eduyrs>13

* Demean years of completed education  (CAPPED)
g eduyrs_actual = eduyrs
label var eduyrs_actual "Years of education (capped at 13)"
sum eduyrs, det
replace eduyrs = eduyrs - `r(mean)'

* Demean years of completed education (NOT CAPPED)
*[necessary for RD estimator below]
g total_eduyrs_actual = total_eduyrs
label var total_eduyrs_actual "Years of education"
sum total_eduyrs, det
replace total_eduyrs = total_eduyrs - `r(mean)'



#### 7. Cluster 
	 
egen cluster=group(Country essround)
	 
	 
	 
	 
	 

	 
####################################
############REFORM DATES############
####################################

#### 1. Define reform treatments

g treatment = 0 if yrbrn!=.
*Austria
replace treatment = 1 if yrbrn>=1951 & cntry=="AT"  
*Belgium 
replace treatment = 1 if yrbrn>=1969 & cntry=="BE"
*Denmark 
replace treatment = 1 if yrbrn>=1947 & cntry=="DK"
*France 
replace treatment = 1 if yrbrn>=1953 & cntry=="FR"
*Greece 
replace treatment = 1 if yrbrn>=1963 & cntry=="GR"
*Iceland 
replace treatment = 1 if yrbrn>=1961 & cntry=="IS"
*Ireland 
replace treatment = 1 if yrbrn>=1958 & cntry=="IE"
*Italy 
replace treatment = 1 if yrbrn>=1950 & cntry=="IT"
*Netherlands
replace treatment = 1 if yrbrn>=1959 & cntry=="NL"
*Norway
replace treatment = 1 if yrbrn>=1947 & cntry=="NO"
*Portugal
replace treatment = 1 if yrbrn>=1956 & cntry=="PT"
*Spain
replace treatment = 1 if yrbrn>=1957 & cntry=="ES"
*Sweden 
replace treatment = 1 if yrbrn>=1951 & cntry=="SE"
*Switzerland 
replace treatment = 1 if yrbrn>=1946 & cntry=="CH"
*United Kingdom 
replace treatment = 1 if yrbrn>=1957 & cntry=="GB"  

label var treatment "Indicator for respondents affected by a country's schooling reform"



#### 2. Running variable
*Distance between the year in which the child reached the age to be eligible for the treatment and the reform year

g running=.
*Austria
replace running = yrbrn-1951 if cntry=="AT"  
*Belgium 
replace running = yrbrn-1969 if cntry=="BE"
*Denmark 
replace running = yrbrn-1947 if cntry=="DK"
*France 
replace running = yrbrn-1953 if cntry=="FR"
*Greece 
replace running = yrbrn-1963 if cntry=="GR"
*Iceland 
replace running = yrbrn-1961 if cntry=="IS"
*Ireland 
replace running = yrbrn-1958 if cntry=="IE"
*Italy 
replace running = yrbrn-1950 if cntry=="IT"
*Netherlands
replace running = yrbrn-1959 if cntry=="NL"
*Norway
replace running = yrbrn-1947 if cntry=="NO"
*Portugal
replace running = yrbrn-1957 if cntry=="PT"
*Spain
replace running = yrbrn-1957 if cntry=="ES"
*Sweden 
replace running = yrbrn-1951 if cntry=="SE"
*Switzerland 
replace running = yrbrn-1946 if cntry=="CH"
*United Kingdom 
replace running = yrbrn-1957 if cntry=="GB"  

label var running "Number of cohorts either side of schooling reform"


#### 3. Generate Label country-reforms
*non-missing if we know the age and taking different values by country

gen reform=""
replace reform = "AT (1966)" if cntry=="AT" & cntry!=""  
replace reform = "BE (1983)" if cntry=="BE" & cntry!=""  
replace reform = "DK (1958)" if cntry=="DK" & cntry!="" 
replace reform = "FR (1967)" if cntry=="FR" & cntry!=""  
replace reform = "GR (1975)" if cntry=="GR" & cntry!=""  
replace reform = "IS (1974)" if cntry=="IS" & cntry!=""  
replace reform = "IE (1972)" if cntry=="IE" & cntry!=""  
replace reform = "IT (1963)" if cntry=="IT" & cntry!=""  
replace reform = "NL (1974)" if cntry=="NL" & cntry!=""  
replace reform = "NO (1959+)" if cntry=="NO" & cntry!=""  
replace reform = "PT (1964)" if cntry=="PT" & cntry!=""  
replace reform = "ES (1970)" if cntry=="ES" & cntry!=""  
replace reform = "SE (1965)" if cntry=="SE" & cntry!=""  
replace reform = "CH (1956+)" if cntry=="CH" & cntry!=""  
replace reform = "GB (1972)" if cntry=="GB" & cntry!=""  

label var reform "Country-reform"







 
####################################
############SAMPLING############
####################################

#### 1. Reform in UK did not apply to Scotland
drop if regiongb==12
  
#### 2. drop people whose age is unknown
drop if Age>=999

#### 3. drop people who are below end of schooling age
keep if Age >18

#### 4. Drop if migration after 6 or missing info 
gen Age_migration=livecnta-yrbrn if brncntr==2
drop if Age_migration<0
drop if Age_migration>6 &  brncntr==2





####################################
############FIRST STAGE ############
####################################

***Check first stage
g r=running

/*UNCOMMENT TO GET FIRST STAGES 

rdrobust eduyrs r if reform==           "AT (1966)"  
rdrobust eduyrs r if reform==            "BE (1983)"  
rdrobust eduyrs r if reform==           "CH (1956+)"
rdrobust eduyrs r if reform==            "DK (1958)"
rdrobust eduyrs r if reform==            "ES (1970)"
rdrobust eduyrs r if reform==           "FR (1967)"
rdrobust eduyrs r if reform==           "GB (1972)" 
rdrobust eduyrs r if reform==            "GR (1975)"
rdrobust eduyrs r if reform==            "IE (1972)"
rdrobust eduyrs r if reform==            "IS (1974)"
rdrobust eduyrs r if reform==            "IT (1963)"
rdrobust eduyrs r if reform==            "NL (1974)"
rdrobust eduyrs r if reform==            "NO (1959+)"
rdrobust eduyrs r if reform==            "PT (1964)"
rdrobust eduyrs r if reform==            "SE (1965)" 
*/

*France, GB, Italy, Portugal, Netherlands have first stage significant at 10% at least
g StrongFS=0
replace StrongFS=1 if reform=="FR (1967)"  | reform=="IT (1963)" | reform=="NL (1974)" | reform=="PT (1964)" |reform=="GB (1972)"


 
 
 




####################################
########### MAIN PAPER  ############
####################################


********** Figure 3.1 **********

	set graphics on
hist Guess_foreign if StrongFS==1 , discrete percent  addplot(pci 0 0 2 0, lcolor(orange) lpattern(longdash) lwidth(medthick)) subtitle("Accuracy of Beliefs: % Foreigners")   legend(off) name(a, replace)

hist Guess_foreign2 if StrongFS==1 , discrete percent  addplot(pci 0 0 2 0, lcolor(orange) lpattern(longdash) lwidth(medthick)) subtitle("Direction of Bias: % Foreigners")   legend(off) name(b, replace)

hist Guess_unemployment if StrongFS==1 , discrete percent  addplot(pci 0 0 25 0, lcolor(orange) lpattern(longdash) lwidth(medthick)) subtitle("Accuracy of Beliefs: % Unemployed")   legend(off) name(c, replace)
 
hist Guess_unemployment2 if StrongFS==1 , discrete percent  addplot(pci 0 0 25 0, lcolor(orange) lpattern(longdash) lwidth(medthick)) subtitle("Direction of Bias: % Unemployed")  legend(off) name(d, replace)
 
graph combine a b c d
graph export "$Main/Figure_3_1.png", replace



********** Figure 4.1 **********

la var eduyrs_actual "Years of education (0-13)"
la var eduyrs "Years of education"
la var Age "Age of respondent (19-123)"
la var Domicile "Rural area (0-4)"
la var Child "Has a child living home (0-1)"
la var Education_dad "Father's education (0-4)"
la var Immigrant "Born outside the country (0-1)"
la var Unemployed "Currently unemployed (0-1)"
la var Interest "Political interest (0-3)"
la var Turnout "Turnout (0-1)"
la var Male "Male (0-1)"
la var distance_date "Days from election (0-1845)"
la var govt_int_left_right "Cabinet ideology (0-10)"
la var Parliament "Trust in parliament (0-10)"
la var Income "Subjective income (0-3)"
la var Ideology "Left-right (0-10)"
la var Migrantsqualityoflife "Immigration good for country (0-10)"
la var Unemplazy "Unemployed are lazy (0-4)"

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 

*Foreign
reg Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround i.Country if  StrongFS==1, vce(cluster cluster)
local N1=e(N)
local chi1=e(N_clust) 
su  Guess_foreign if e(sample), mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall)  levels(95) ///
	   lwidth(thin)  legend(off)  xscale(range(-5  5))  xlabel(-5(2)5) ///
	    xline(0, lcolor(black) lpattern(longdash) lwidth(medthin)) title("")  /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 4 (in 2008) and 8 (in 2016)." "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Main/Figure_4_1a.png", replace

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 

*Unemployed 
reg Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround i.Country if  StrongFS==1, vce(cluster cluster)
local N1=e(N)
local chi1=e(N_clust) 
su Guess_unemployment if e(sample),mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall) levels(95) ///
	   lwidth(medthin)  xscale(range(-1.25 1.25))  xlabel(-1.25(0.5)1.25)  legend(off)  ///
	   pstyle(p3)   xline(0, lcolor(black)   lpattern(longdash) lwidth(thin)) title("")  /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 1 (in 2002) and 7 (in 2014)."  "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Main/Figure4_1b.png", replace
 

 
 
 
********** Figure 4.2 **********
	
 grstyle init
	 grstyle set legend 12,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title 
    grstyle set graphsize 12cm 15cm

rdplot Guess_foreign running if  running>=-20 & running<=20 &  StrongFS==1,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) title("") ytitle("Accuracy: % Foreigners") xtitle("Cohort relative to reform")   ylabel(#3))  note("")  yscale(range(-25  -5))  ylabel(-25(5)-5) 
graph export "$Main/Figure4_2a.png", replace

rdplot Guess_unemployment  running if  running>=-20 & running<=20 &  StrongFS==1,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) ylab(,nogrid)  title("") ytitle("Accuracy: % Unemployed") xtitle("Cohort relative to reform") )  note("") 
graph export "$Main/Figure4_2b.png", replace





********** Figure 4.3 **********
	
 grstyle init
	 grstyle set legend 12,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title 
    grstyle set graphsize 12cm 15cm


rdplot Guess_foreign running if  running>=-20 & running<=20 &  StrongFS==1 & Edu_dad_dummy==0 ,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) title("% Foreigners, low-SES", size(large)) ytitle("Accuracy % Foreigners") xtitle("Cohort relative to reform")   ylabel(#3))  note("")  yscale(range(-25  -5))  ylabel(-25(5)-5) 
graph export "$Main/Figure4_3a.png", replace
 
rdplot Guess_foreign running if  running>=-20 & running<=20 &  StrongFS==1 & Edu_dad_dummy==1,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) title("% Foreigners, high-SES", size(large)) ytitle("Accuracy % Foreigners") xtitle("Cohort relative to reform")   ylabel(#3))  note("")  yscale(range(-25  -5))  ylabel(-25(5)-5) 
graph export "$Main/Figure4_3b.png", replace
 
rdplot Guess_unemployment  running if  running>=-20 & running<=20 &  StrongFS==1  & Edu_dad_dummy==0 ,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) ylab(,nogrid)  title("% Unemployed, low-SES", size(large)) ytitle("Accuracy % Unemployed") xtitle("Cohort relative to reform") )  note("") 
graph export "$Main/Figure4_3c.png", replace
 
rdplot Guess_unemployment  running if  running>=-20 & running<=20 &  StrongFS==1  & Edu_dad_dummy==1 ,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) ylab(,nogrid)  title("% Unemployed, high-SES", size(large)) ytitle("Accuracy % Unemployed") xtitle("Cohort relative to reform") )  note("") 
graph export "$Main/Figure4_3d.png", replace















###########################
##### APPPENDIX
###########################

********** Table A.2 **********

est clear

matrix RDROBUST_matrix = J(6,3,0)
matrix rownames RDROBUST_matrix = "Reform" "SE" "p-value" "Bandwidth" "N." "Mean"
matrix colnames RDROBUST_matrix = "(1)" "(2)" "(3)"
local i=0
			local i=`i'+1
			quietly rdrobust eduyrs running if country!="Germany" & country!="Finland" , p(1) c(0) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'

			local i=`i'+1
			quietly rdrobust eduyrs running if country!="Germany" & country!="Finland" , p(1) c(0) covs(r1 r2 r3 r4 r5 r6 r7 r8 r9)
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'

			local i=`i'+1
			quietly rdrobust eduyrs running if country!="Germany" & country!="Finland" , p(1) c(0) covs(r1 r2 r3 r4 r5 r6 r7 r8 r9 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 )
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'

estout matrix(RDROBUST_matrix, fmt("5 3 4 0 0 2")) using "$Appendix\Table_A_2.tex", style(tex) replace starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001)




********** Figure A.1 **********

est clear
quietly rdrobust eduyrs r if StrongFS==1 , p(1)
estimates store ALL
quietly rdrobust eduyrs r if reform=="FR (1967)" , p(1)
estimates store FR
quietly rdrobust eduyrs r if reform=="IT (1963)" , p(1)
estimates store IT
quietly rdrobust eduyrs r if reform=="NL (1974)" , p(1)
estimates store NL
quietly rdrobust eduyrs r if reform=="PT (1964)" , p(1)
estimates store PT
quietly rdrobust eduyrs r if reform=="GB (1972)" , p(1)
estimates store UK

  grstyle init
 grstyle set legend 2,  nobox
 grstyle set size 8pt: tick_label key_label
 grstyle set size 12pt: heading
 grstyle set size 10pt: subheading axis_title
 grstyle set graphsize 13cm 13cm
coefplot (ALL, aseq(Pooled (All)) \ FR,aseq(France ('67)) \ IT,aseq(Italy ('63)) \ NL, aseq(Netherlands ('74))\ PT , aseq(Portugal ('64)) \ UK , aseq(United Kingdom ('72)) )  , replace  swapnames   xline(0, lpattern(dash) lcolor(black)) msymbol(s)  levels(90)  ciopts(recast(. rcap))   yscale(alt noline)  legend(off)  subtitle("{bf:Treatment effects}")  baselevels 
graph save Graph "$Appendix\Figure_A_1a.gph", replace
graph export "$Appendix\Figure_A_1a.png", replace
erase "$Appendix\Figure_A_1a.gph" 


*no first stage
est clear 
quietly rdrobust eduyrs r if StrongFS!=1 , p(1)
estimates store ALL
quietly rdrobust eduyrs r if reform=="AT (1966)" , p(1)
estimates store AT
quietly rdrobust eduyrs r if reform=="BE (1983)" , p(1)
estimates store BE
quietly rdrobust eduyrs r if reform=="DK (1958)" , p(1)
estimates store DK
quietly rdrobust eduyrs r if reform=="GR (1975)" , p(1)
estimates store GR
quietly rdrobust eduyrs r if reform=="IS (1974)" , p(1)
estimates store IS
quietly rdrobust eduyrs r if reform=="IE (1972)" , p(1)
estimates store IE
quietly rdrobust eduyrs r if reform=="NO (1959+)" , p(1)
estimates store NO
quietly rdrobust eduyrs r if reform=="ES (1970)" , p(1)
estimates store ES
quietly rdrobust eduyrs r if reform=="SE (1965)" , p(1)
estimates store SE
quietly rdrobust eduyrs r if reform=="CH (1956+)" , p(1)
estimates store CH

  grstyle init
 grstyle set legend 2,  nobox
 grstyle set size 8pt: tick_label key_label
 grstyle set size 12pt: heading
 grstyle set size 10pt: subheading axis_title
 grstyle set graphsize 13cm 13cm
coefplot (ALL, aseq(Pooled (All)) \ AT, aseq(Austria ('66)) \ BE, aseq(Belgium ('83)) \ DK, aseq(Denmark ('58)) \ GR, aseq(Greece ('75)) \ IE , aseq(Ireland ('72)) \ IS , aseq(Iceland ('74)) \ NO , aseq(Norway ('69)) \ ES,aseq(Spain ('69)) \ CH, aseq(Sweden ('65)) \ CH, aseq(Switzerland ('56)) )  , replace  swapnames   xline(0, lpattern(dash) lcolor(black)) msymbol(s)  levels(90)  ciopts(recast(. rcap))   yscale(alt noline)  legend(off)  subtitle("{bf:Treatment effects}")  baselevels 
graph save Graph "$Appendix\Figure_A_1b.gph", replace
graph export "$Appendix\Figure_A_1b.png", replace
erase "$Appendix\Figure_A_1b.gph" 





********** Table A.3 **********

preserve
keep if   StrongFS==1

la var total_eduyrs_actual "Years of education"
la var Guess_foreign "Beliefs accuracy: \% foreigners"
la var Guess_unemployment "Beliefs accuracy: \% unemployed"
la var Guess_foreign2 "Beliefs bias: \% foreigners"
la var Guess_unemployment2 "Beliefs bias: \% unemployed"
la var Noanswer "Non-response: \% foreigners"
la var Noanswer2 "Non-response: \% unemployed"

estpost sum  Guess_foreign Guess_unemployment Guess_foreign2 Guess_unemployment2 Noanswer Noanswer2 total_eduyrs_actual  Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife Unemplazy govt_int_left_right distance_date
est store a
esttab a   

esttab a using "$Appendix\Table_A_3.tex" , replace ///
style(tex)  refcat(Guess_foreign "\textbf{{Dependent Variables}}"  total_eduyrs_actual "\textbf{{Independent Variables}}" Age   "\textbf{{Demographics}}"  Interest "\textbf{{Politicization}}"  Migrantsqualityoflife "\textbf{{Political attitudes}}" govt_int_left_right "\textbf{{Contextual variables}}", nolabel) ///
 cells("mean(fmt(2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2   )) sd(fmt(2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2  )) min(fmt(0 2 0 0 0 0 0 0 0 0  0 0 0 0 0  0 0 2 0))  max(fmt(0 2 0 0 0 0 0 0 0 0  0 0 0 0 0  0 0 2 0  )) count(fmt(0 0 0 0 0 0 0 0 0 0  0 0 0 0 0  0 0 0 0  ))") varwidth(10)  label nonumber  noobs booktabs   
restore 




********** Table B.4 **********

est clear
capture noisily eststo: reg Guess_foreign eduyrs if  StrongFS==1, cluster(cluster) 
		estadd loc country "No", replace							
		estadd loc wave "No", replace							

capture noisily eststo: reghdfe Guess_foreign eduyrs if  StrongFS==1, cluster(cluster) absorb(essround Country) 
		estadd loc country "Yes", replace							
		estadd loc wave "Yes", replace							

capture noisily eststo: reghdfe Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date if  StrongFS==1, cluster(cluster) absorb(essround Country) 
		estadd loc country "Yes", replace							
		estadd loc wave "Yes", replace							

capture noisily eststo: reg Guess_unemployment eduyrs if  StrongFS==1, cluster(cluster) 
		estadd loc country "No", replace							
		estadd loc wave "No", replace							

capture noisily eststo: reghdfe Guess_unemployment eduyrs if  StrongFS==1, cluster(cluster) absorb(essround Country) 
		estadd loc country "Yes", replace							
		estadd loc wave "Yes", replace							

		capture noisily eststo: reghdfe Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date if  StrongFS==1, cluster(cluster) absorb(essround Country) 
		estadd loc country "Yes", replace							
		estadd loc wave "Yes", replace							

esttab est* using "$Appendix/Table_B_4", star(* .1 ** .05 *** .01) se b(3) r2 ///
order(eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology govt_int_left_right distance_date Migrantsqualityoflife Unemplazy) ///
s(country wave N r2 N_clust , ///
label("Country FE" "Wave FE" "Observations" "R-squared" "N. Clusters") ///
fmt(0 0 0 3 0)) ///
replace tex nonotes label	




********** Figure B.1 **********

la var Guess_foreign "Beliefs Accuracy: % Foreigners"
la var Guess_unemployment "Beliefs Accuracy: % Unemployed"
la var Guess_foreign2 "Beliefs Bias: % Foreigners"
la var Guess_unemployment2 "Beliefs Bias: % Unemployed"

la var total_eduyrs_actual "Years of education (0-65)"
la var eduyrs_actual "Years of education (0-13)"
la var eduyrs "Years of education"
la var Age "Age of respondent (19-123)"
la var Domicile "Rural area (0-4)"
la var Child "Has a child living home (0-1)"
la var Education_dad "Father's education (0-4)"
la var Immigrant "Born outside the country (0-1)"
la var Unemployed "Currently unemployed (0-1)"
la var Interest "Political interest (0-3)"
la var Turnout "Turnout (0-1)"
la var Male "Male (0-1)"
la var distance_date "Days from election (0-1845)"
la var govt_int_left_right "Cabinet ideology (0-10)"
la var Parliament "Trust in parliament (0-10)"
la var Income "Subjective income (0-3)"
la var Ideology "Left-right (0-10)"
la var Migrantsqualityoflife "Immigration good for country (0-10)"
la var Unemplazy "Unemployed are lazy (0-4)"


	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 

	quietly: reg Guess_foreign total_eduyrs_actual Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround i.Country if  StrongFS==1, vce(cluster cluster)
local N1=e(N)
local chi1=e(N_clust) 
su  Guess_foreign if e(sample), mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall)  levels(95) ///
	   lwidth(thin)  legend(off)  xscale(range(-5  5))  xlabel(-5(2)5) ///
	    xline(0, lcolor(black) lpattern(longdash) lwidth(medthin)) title("") /// 
	   headings(total_eduyrs_actual = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 4 (in 2008) and 8 (in 2016)." "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_B_1a.png", replace

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 

	quietly: reg Guess_unemployment total_eduyrs_actual Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround i.Country if  StrongFS==1, vce(cluster cluster)
local N1=e(N)
local chi1=e(N_clust) 
su Guess_unemployment if e(sample),mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall) levels(95) ///
	   lwidth(medthin)  xscale(range(-1.25 1.25))  xlabel(-1.25(0.5)1.25)  legend(off)  ///
	   pstyle(p3)   xline(0, lcolor(black)   lpattern(longdash) lwidth(thin)) title("") /// 
	   headings(total_eduyrs_actual = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 1 (in 2002) and 7 (in 2014)."  "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_B_1b.png", replace




********** Figure B.2 **********

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 

	quietly: reg Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround i.Country, vce(cluster cluster)
local N1=e(N)
local chi1=e(N_clust) 
su  Guess_foreign if e(sample), mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall)  levels(95) ///
	   lwidth(thin)  legend(off)  xscale(range(-5  5))  xlabel(-5(2)5) ///
	    xline(0, lcolor(black) lpattern(longdash) lwidth(medthin)) title("") /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 4 (in 2008) and 8 (in 2016)." "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_B_2a.png", replace

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 

	quietly: reg Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround i.Country, vce(cluster cluster)
local N1=e(N)
local chi1=e(N_clust) 
su Guess_unemployment if e(sample),mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall) levels(95) ///
	   lwidth(medthin)  xscale(range(-1.25 1.25))  xlabel(-1.25(0.5)1.25)  legend(off)  ///
	   pstyle(p3)   xline(0, lcolor(black)   lpattern(longdash) lwidth(thin)) title("") /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 1 (in 2002) and 7 (in 2014)."  "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_B_2b.png", replace




********** Figure B.3 **********

*FOREIGNERS
*First find the bandwidth
rdrobust Guess_foreign running if StrongFS==1,  covs(r1 r4 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 ) 
gen bandwidth=e(h_l)

preserve 

*Restrict the sample
keep if abs(running)<=abs(bandwidth) & StrongFS==1 & Guess_foreign!=.

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 

	quietly: reg Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround i.Country, vce(cluster cluster)
local N1=e(N)
local chi1=e(N_clust) 
su  Guess_foreign if e(sample), mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall)  levels(95) ///
	   lwidth(thin)  legend(off)  xscale(range(-5  5))  xlabel(-5(2)5) ///
	    xline(0, lcolor(black) lpattern(longdash) lwidth(medthin)) title("") /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 4 (in 2008) and 8 (in 2016)." "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_B_3a.png", replace

restore 

*UNEMPLOYED
*First find the bandwidth
drop bandwidth
rdrobust Guess_unemployment running if StrongFS==1,  covs(r1 r4 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 ) 
gen bandwidth=e(h_l)

preserve 

*Restrict the sample
keep if abs(running)<=abs(bandwidth) & StrongFS==1 & Guess_unemployment!=.

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 

	quietly: reg Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround i.Country, vce(cluster cluster)
local N1=e(N)
local chi1=e(N_clust) 
su Guess_unemployment if e(sample),mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall) levels(95) ///
	   lwidth(medthin)  xscale(range(-1.25 1.25))  xlabel(-1.25(0.5)1.25)  legend(off)  ///
	   pstyle(p3)   xline(0, lcolor(black)   lpattern(longdash) lwidth(thin)) title("") /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 1 (in 2002) and 7 (in 2014)."  "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_B_3b.png", replace

restore 






  
  
********** Figure B.4 **********
	
***FOREIGNERS 
est clear 
quietly: reg Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround   if  cntry=="FR" , vce(robust)
est store fr

quietly: reg Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround   if  cntry=="IT" , vce(robust)
est store it

quietly: reg Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround   if  cntry=="NL" , vce(robust)
est store nl

quietly: reg Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround   if  cntry=="PT" , vce(robust)
est store pt

quietly: reg Guess_foreign eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround   if  cntry=="GB" , vce(robust)
est store gb


	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
	 grstyle set color: black 
 	   coefplot  fr it nl pt gb ///
     , keep(eduyrs) pstyle(p1)   msymbol(o) mcolor(black) msize(medsmall)  levels(95) aseq swapnames ///
	   coeflabels(fr = "France"   ///
			   it = "Italy"  ///
               nl = "Netherlands"  ///
			   pt = "Portugal"  ///
			   gb = "United Kingdom" )  /// 
			lwidth(thin)     xscale(range(-2  2))  xlabel(-2(1)2) ///
	    xline(0, lcolor(black) lpattern(longdash) lwidth(medthin)) title("") legend(off)  /// 
      note("Controls and round effects as in main specification. Heteroskedasticity-robust standard errors." "The output variable is available for ESS rounds 4 (in 2008) and 8 (in 2016).", size(small) span)
graph export "$Appendix/Figure_B_4a.png", replace	  
	  

***UNEMPLOYMENT  
est clear   
quietly: reg Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround   if  cntry=="FR" , vce(robust)
est store fr2

reg Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround   if  cntry=="IT" , vce(robust)
est store it2

quietly: reg Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround   if  cntry=="NL" , vce(robust)
est store nl2

quietly: reg Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround   if  cntry=="PT" , vce(robust)
est store pt2

quietly: reg Guess_unemployment eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround   if  cntry=="GB" , vce(robust)
est store gb2


	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
	 grstyle set color: black 
 	   coefplot  fr2 it2 nl2 pt2 gb2 ///
     , keep(eduyrs) pstyle(p1)   msymbol(o) mcolor(black) msize(medsmall)  levels(95) aseq swapnames ///
	   coeflabels(fr2 = "France"   ///
			   it2 = "Italy"  ///
               nl2 = "Netherlands"  ///
			   pt2 = "Portugal"  ///
			   gb2 = "United Kingdom" )  /// 
			lwidth(thin)     xscale(range(-0.5  0.5))  xlabel(-0.5(0.2)0.5) ///
	    xline(0, lcolor(black) lpattern(longdash) lwidth(medthin)) title("") legend(off)  /// 
      note("Controls and round effects as in main specification. Heteroskedasticity-robust standard errors." "The output variable is available for ESS rounds 1 (in 2002) and 7 (in 2014).", size(small) span)
graph export "$Appendix/Figure_B_4b.png", replace	  






********** Figure C.1 **********

*Density of data either side of the reform, pooled across countries
DCdensity r if StrongFS==1 , breakpoint(0) b(1) h(5) generate(Xj Yj r0 fhat se_fhat)
graph save Graph "$Appendix\g_all.gph", replace
drop Xj Yj r0 fhat se_fhat
*Density by country
foreach x in "FR (1967)" "IT (1963)" "NL (1974)" "PT (1964)" "GB (1972)" {
	di "******************** Country = `x' **********************"
	DCdensity r if reform=="`x'", breakpoint(0) b(1) h(5) generate(Xj Yj r0 fhat se_fhat)
	graph save Graph "$Appendix\g_`x'.gph", replace
	drop Xj Yj r0 fhat se_fhat
}
gr combine "$Appendix\g_all.gph" "$Appendix\g_FR (1967).gph" "$Appendix\g_IT (1963).gph" "$Appendix\g_NL (1974).gph" "$Appendix\g_PT (1964).gph" "$Appendix\g_GB (1972).gph" , rows(2) cols(3) subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
graph save Graph "$Appendix\Figure_C_1.gph", replace
graph export "$Appendix\Figure_C_1.png", replace

foreach x in "FR (1967)" "IT (1963)" "NL (1974)" "PT (1964)" "GB (1972)" {
erase "$Appendix\g_`x'.gph"
}
erase "$Appendix\g_all.gph"



********** Table C.5 **********

*generate ESS wave dummies (not used)
tabulate essround, gen(round_)

est clear

matrix ALL_BALANCE = J(6,3,0)
matrix rownames ALL_BALANCE = "Reform" "SE" "p-value" "Bandwidth" "N." "Mean"
matrix colnames ALL_BALANCE = "(1)" "(2)" "(3)" 
local i=0

quietly foreach y of varlist Male Edu_dad_dummy Edu_mum_dummy {

	quietly sum `y', det
	gen `y'_dem= `y' - `r(mean)'
	label var `y'_dem "Demeaned `y'"

	local i=`i'+1
	quietly rdrobust `y'_dem r if StrongFS==1 , c(0) p(1)
	matrix ALL_BALANCE[1,`i'] = e(tau_cl)
	matrix ALL_BALANCE[2,`i'] = e(se_tau_cl)
	matrix ALL_BALANCE[3,`i'] = e(pv_cl)
	matrix ALL_BALANCE[4,`i'] = floor(e(h_l))
	matrix ALL_BALANCE[5,`i'] = e(N_h_l) + e(N_h_r)
	sum `y' if r>=-floor(e(h_l)) & r<=floor(e(h_l))
	matrix ALL_BALANCE[6,`i'] = `r(mean)'
	drop `y'_dem
	}
	
estout matrix(ALL_BALANCE, fmt("3 3 4 0 0 2")) using "$Appendix\Table_C_5.tex", style(tex) replace
 



********** Figure C.2 **********

global pcomp "Guess_foreign Guess_unemployment"

quietly foreach y of global pcomp {

	matrix A_`y' = J(19,5,0)
	
	foreach b of numlist 2(1)20 {
		matrix A_`y'[`b'-1,1] = `b'
		rdrobust `y' r if StrongFS==1 , p(1) c(0) h(`b') 
		matrix A_`y'[`b'-1,2] = e(tau_cl)
		matrix A_`y'[`b'-1,3] = e(tau_cl) - 1.96 * e(se_tau_cl)
		matrix A_`y'[`b'-1,4] = e(tau_cl) + 1.96 * e(se_tau_cl)
		matrix A_`y'[`b'-1,5] = e(N_h_l) + e(N_h_r)
	}

	preserve
	svmat A_`y'
	twoway (scatter A_`y'2 A_`y'1 if A_`y'1>=2 & A_`y'1<=20, mcolor(gs10 msize(small))) ///
		(rcap A_`y'3 A_`y'4 A_`y'1 if A_`y'1>=2 & A_`y'1<=20, vertical lcolor(gs10 lwidth(thick))), ///
		legend(off) graphregion(fcolor(white) lcolor(white)) ylab(, nogrid) ylabel(#3) yline(0, lcolor(orange) lpattern(longdash)) ///
		title(`: variable label `y'', size(medsmall) color(black)) ytitle("Estimate") xtitle("Bandwidth") legend(off)
	graph save Graph "$Appendix\g_`y'.gph", replace
	restore

graph save Graph "$Appendix\Figure_C_2_`y'.gph", replace
graph export "$Appendix\Figure_C_2_`y'.png", replace
erase "$Appendix\g_`y'.gph" 

}
 



 
 
********** Table C.6 **********

est clear
global pcomp "Guess_foreign Guess_unemployment"

matrix RDROBUST_matrix = J(6,6,0)
matrix rownames RDROBUST_matrix = "Reform" "SE" "p-value" "Bandwidth" "N." "Mean"
matrix colnames RDROBUST_matrix = "(1)" "(2)" "(3)" "(4)" "(5)" "(6)"
local i=0
quietly foreach y of global pcomp{
		quietly foreach poly of numlist 1/3 {	
				local i=`i'+1
			quietly rdrobust `y' r if StrongFS==1 , p(`poly') c(0) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum `y' if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'
	}
	
}

estout matrix(RDROBUST_matrix, fmt("5 3 4 0 0 2")) using "$Appendix\Table_C_6a.tex", style(tex) replace starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001)
 

#### Rectangular Kernel

est clear
global pcomp "Guess_foreign Guess_unemployment"

matrix RDROBUST_matrix = J(6,6,0)
matrix rownames RDROBUST_matrix = "Reform" "SE" "p-value" "Bandwidth" "N." "Mean"
matrix colnames RDROBUST_matrix = "(1)" "(2)" "(3)" "(4)" "(5)" "(6)"
local i=0
quietly foreach y of global pcomp{
		quietly foreach poly of numlist 1/3 {	
				local i=`i'+1
			quietly rdrobust `y' r if StrongFS==1 , p(`poly') c(0) kernel(uniform) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum `y' if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'
	}
	
}

estout matrix(RDROBUST_matrix, fmt("5 3 4 0 0 2")) using "$Appendix\Table_C_6b.tex", style(tex) replace starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001)
 



 
 
********** Figure C.3 **********

rdplot Guess_foreign running if running>=-20 & running<=20 & cntry=="FR", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("France") ytitle("") xtitle("") )  note("") 
graph save fr, replace
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry=="IT",   c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Italy") ytitle("") xtitle("") )  note("") 
graph save it, replace
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry=="NL", legend(off)  c(0) p(1) ci(95)  graph_options( legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Netherlands") ytitle("") xtitle("") )  note("") 
graph save nl, replace
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry=="PT", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off) graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Portugal") ytitle("") xtitle("") )  note("") 
graph save pt, replace
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry=="GB", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("United Kingdom") ytitle("") xtitle("") )  note("") 
graph save gb, replace
rdplot Guess_foreign running if running>=-20 & running<=20, legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white) ) ylab(,nogrid labsize(small))     title("All Countries") ytitle("") xtitle("") )  note("") 
graph save all, replace

graph combine all.gph fr.gph it.gph nl.gph pt.gph gb.gph, rows(2) cols(3)  ycommon  iscale(.55)  
graph export "$Appendix\Figure_C_3.png", replace




********** Figure C.4 **********
	
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry=="FR", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("France") ytitle("") xtitle("") )  note("") 
graph save fr2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry=="IT",   c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Italy") ytitle("") xtitle("") )  note("") 
graph save it2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry=="NL", legend(off)  c(0) p(1) ci(95)  graph_options( legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Netherlands") ytitle("") xtitle("") )  note("") 
graph save nl2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry=="PT", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off) graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Portugal") ytitle("") xtitle("") )  note("") 
graph save pt2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry=="GB", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("United Kingdom") ytitle("") xtitle("") )  note("") 
graph save gb2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20, legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white) ) ylab(,nogrid labsize(small))     title("All Countries") ytitle("") xtitle("") )  note("") 
graph save all2, replace

graph combine all2.gph fr2.gph it2.gph nl2.gph pt2.gph gb2.gph, rows(2) cols(3)  ycommon  iscale(.55)  
graph export "$Appendix\Figure_C_4.png", replace

foreach x in all fr it nl pt gb {
	erase "`x'.gph" 
	erase "`x'2.gph" 		
}





********** Figure C.5 **********
	
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry!="FR", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("France") ytitle("") xtitle("") )  note("") 
graph save fr, replace
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry!="IT",   c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Italy") ytitle("") xtitle("") )  note("") 
graph save it, replace
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry!="NL", legend(off)  c(0) p(1) ci(95)  graph_options( legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Netherlands") ytitle("") xtitle("") )  note("") 
graph save nl, replace
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry!="PT", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off) graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Portugal") ytitle("") xtitle("") )  note("") 
graph save pt, replace
rdplot Guess_foreign running if running>=-20 & running<=20 & cntry!="GB", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("United Kingdom") ytitle("") xtitle("") )  note("") 
graph save gb, replace
rdplot Guess_foreign running if running>=-20 & running<=20, legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white) ) ylab(,nogrid labsize(small))     title("All Countries") ytitle("") xtitle("") )  note("") 
graph save all, replace

graph combine all.gph fr.gph it.gph nl.gph pt.gph gb.gph, rows(2) cols(3)  ycommon  iscale(.55)  
graph export "$Appendix\Figure_C_5.png", replace




********** Figure C.6 **********
	
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry!="FR", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("France") ytitle("") xtitle("") )  note("") 
graph save fr2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry!="IT",   c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Italy") ytitle("") xtitle("") )  note("") 
graph save it2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry!="NL", legend(off)  c(0) p(1) ci(95)  graph_options( legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Netherlands") ytitle("") xtitle("") )  note("") 
graph save nl2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry!="PT", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off) graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("Portugal") ytitle("") xtitle("") )  note("") 
graph save pt2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20 & cntry!="GB", legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white)) ylab(,nogrid labsize(small))  title("United Kingdom") ytitle("") xtitle("") )  note("") 
graph save gb2, replace
rdplot Guess_unemployment running if running>=-20 & running<=20, legend(off)  c(0) p(1) ci(95)  graph_options(legend(off)  graphregion(fcolor(white) lcolor(white) ) ylab(,nogrid labsize(small))     title("All Countries") ytitle("") xtitle("") )  note("") 
graph save all2, replace

graph combine all2.gph fr2.gph it2.gph nl2.gph pt2.gph gb2.gph, rows(2) cols(3)  ycommon  iscale(.55)  
graph export "$Appendix\Figure_C_6.png", replace

foreach x in all fr it nl pt gb {
	erase "`x'.gph" 
	erase "`x'2.gph" 		
}




********** Figure C.7 **********

est clear
global pcomp "Guess_foreign Guess_unemployment"

quietly foreach y of global pcomp {
	matrix A_`y' = J(11,5,0)
	
	foreach b of numlist -5(1)5 {
		matrix A_`y'[`b'+6,1] = `b'
		rdrobust `y' r if StrongFS==1, p(1) c(`b') 
		matrix A_`y'[`b'+6,2] = e(tau_cl)
		matrix A_`y'[`b'+6,3] = e(tau_cl) - 1.96 * e(se_tau_cl)
		matrix A_`y'[`b'+6,4] = e(tau_cl) + 1.96 * e(se_tau_cl)
		matrix A_`y'[`b'+6,5] = e(N_h_l) + e(N_h_r)
	}

	preserve
	svmat A_`y'
	twoway (scatter A_`y'2 A_`y'1 if A_`y'1>=-5 & A_`y'1<=5 & A_`y'2!=0, mcolor(gs10) msize(small) yscale(range(-0.05 0.05)) yline(0)) ///
		(rcap A_`y'3 A_`y'4 A_`y'1 if A_`y'1>=-5 & A_`y'1<=5 & A_`y'2!=0, vertical lcolor(gs10) lwidth(thick)), ///
		legend(off) graphregion(fcolor(white) lcolor(white)) ylab(, nogrid)  ylabel(#5) xlabel(#11)  ///
		title(`: variable label `y'', size(medsmall) color(black)) ytitle("Estimate") xtitle("Placebo Date (Years Distance from Real Date)") legend(off)
*	twoway (scatter A_`y'2 A_`y'1 if A_`y'1>=-5 & A_`y'1<=5 & A_`y'2!=0, mcolor(gs10) msize(small) yscale(range(-0.5 0.5)) yline(0)) ///
*		(rcap A_`y'3 A_`y'4 A_`y'1 if A_`y'1>=-5 & A_`y'1<=5 & A_`y'2!=0, vertical lcolor(gs10) lwidth(thick)), ///
*		legend(off) graphregion(fcolor(white) lcolor(white)) ylab(, nogrid)  ylabel(#5) xlabel(#11)  ///
*		title(`: variable label `y'', size(medsmall) color(black)) ytitle("Estimate") xtitle("Placebo Date (Years Distance from Real Date)") legend(off)
	graph save Graph "$Appendix/Figure_C_7_`y'.gph", replace
	graph export "$Appendix/Figure_C_7_`y'.png", replace
	restore
} 






********** Figure D.1 **********

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 
quietly: reg Guess_foreign2 eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround i.Country if  StrongFS==1, cluster(cluster)
local N1=e(N)
local chi1=e(N_clust) 
su  Guess_foreign2 if e(sample), mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall)  levels(95) ///
	   lwidth(thin)  legend(off)  xscale(range(-5  5))  xlabel(-5(2)5) ///
	    xline(0, lcolor(black) lpattern(longdash) lwidth(medthin)) title("")  /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 4 (in 2008) and 8 (in 2016)." "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_D_1a.png", replace



	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 
quietly: reg Guess_unemployment2 eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround i.Country if  StrongFS==1, cluster(cluster)
local N1=e(N)
local chi1=e(N_clust) 
su Guess_unemployment2 if e(sample),mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall) levels(95) ///
	   lwidth(medthin)  xscale(range(-1.25 1.25))  xlabel(-1.25(0.5)1.25)  legend(off)  ///
	   pstyle(p3)   xline(0, lcolor(black)   lpattern(longdash) lwidth(thin)) title("")  /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 1 (in 2002) and 7 (in 2014)."  "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_D_1b.png", replace





********** Figure D.2 **********
	
 grstyle init
	 grstyle set legend 12,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title 
    grstyle set graphsize 12cm 15cm
rdplot Guess_foreign2 running if  running>=-20 & running<=20 &  StrongFS==1,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) title("") ytitle("Bias % Foreigners") xtitle("Cohort relative to reform")   ylabel(#3))  note("")  yscale(range(-25  -5))  ylabel(-25(5)-5) 
graph export "$Appendix/Figure_D_2a.png", replace

rdplot Guess_unemployment2 running if  running>=-20 & running<=20 &  StrongFS==1,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) ylab(,nogrid)  title("") ytitle("Bias % Unemployed") xtitle("Cohort relative to reform") )  note("") 
graph export "$Appendix/Figure_D_2b.png", replace




********** Table D.7 **********

est clear
capture noisily eststo: reg Guess_foreign2 eduyrs if  StrongFS==1, cluster(cluster) 
		estadd loc country "No", replace							
		estadd loc wave "No", replace							

capture noisily eststo: reghdfe Guess_foreign2 eduyrs if  StrongFS==1, cluster(cluster) absorb(essround Country) 
		estadd loc country "Yes", replace							
		estadd loc wave "Yes", replace							

capture noisily eststo: reghdfe Guess_foreign2 eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date if  StrongFS==1, cluster(cluster) absorb(essround Country) 
		estadd loc country "Yes", replace							
		estadd loc wave "Yes", replace							

capture noisily eststo: reg Guess_unemployment2 eduyrs if  StrongFS==1, cluster(cluster) 
		estadd loc country "No", replace							
		estadd loc wave "No", replace							

capture noisily eststo: reghdfe Guess_unemployment2 eduyrs if  StrongFS==1, cluster(cluster) absorb(essround Country) 
		estadd loc country "Yes", replace							
		estadd loc wave "Yes", replace							

		capture noisily eststo: reghdfe Guess_unemployment2 eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date if  StrongFS==1, cluster(cluster) absorb(essround Country) 
		estadd loc country "Yes", replace							
		estadd loc wave "Yes", replace							

esttab est* using "$Appendix/Table_D_7", star(* .1 ** .05 *** .01) se b(3) r2 ///
order(eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology govt_int_left_right distance_date Migrantsqualityoflife Unemplazy) ///
s(country wave N r2 N_clust , ///
label("Country FE" "Wave FE" "Observations" "R-squared" "N. Clusters") ///
fmt(0 0 0 3 0)) ///
replace tex nonotes label	





********** Figure E.1 **********

drop Noanswer* 

g Noanswer=.
replace Noanswer=0 if essround==1 & noimbro!=.
replace Noanswer=0 if essround==7 & noimbro!=. 
replace Noanswer=1 if noimbro==. & essround==1 
replace Noanswer=1 if noimbro==. & essround==7
la var Noanswer "Miss. Answer: % Foreigners"

g Noanswer2=.
replace Noanswer2=0 if essround==4 & uemplwk!=.
replace Noanswer2=0 if essround==8 & uemplwk!=. 
replace Noanswer2=1 if uemplwk==. & essround==4
replace Noanswer2=1 if uemplwk==. & essround==8
la var Noanswer2 "Miss. Answer: % Unemployed"



	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 
quietly: reg Noanswer eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Migrantsqualityoflife govt_int_left_right distance_date i.essround i.Country if  StrongFS==1, cluster(cluster)
local N1=e(N)
local chi1=e(N_clust) 
su  Noanswer if e(sample), mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall)  levels(95) ///
	   lwidth(thin)  legend(off)  xscale(range(-0.05 0.05))  xlabel(-0.05(0.01)0.05) ///
	    xline(0, lcolor(black) lpattern(longdash) lwidth(medthin)) title("")  /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 4 (in 2008) and 8 (in 2016)." "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_E_1a.png", replace


	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
    grstyle set graphsize 15cm 17cm 
reg Noanswer2 eduyrs Age Male  Child Domicile Immigrant Unemployed Income Education_dad Interest Turnout Parliament Ideology Unemplazy govt_int_left_right distance_date i.essround i.Country if  StrongFS==1, cluster(cluster)
local N1=e(N)
local chi1=e(N_clust) 
su Noanswer2 if e(sample),mean
loc Meanm:di%8.1fc r(mean)
est store a1
 	   coefplot  a1 ///
     , drop(_cons *.essround *.Country) msymbol(o) mcolor(black) msize(medsmall) levels(95) ///
	   lwidth(medthin)  xscale(range(-0.05 0.05))  xlabel(-0.05(0.01)0.05)  legend(off)  ///
	   pstyle(p3)   xline(0, lcolor(black)   lpattern(longdash) lwidth(thin)) title("")  /// 
	   headings(eduyrs = "{bf:Main coefficient}"    ///
	    Age = "{bf:Demographics}"   ///     
	    Unemployed = "{bf:SES}"   /// 
        Interest= "{bf:Politicization}" ///
		Ideology= "{bf:Ideology}" ///
		govt_int_left_right= "{bf:Political context}") ///
      note("Controls for country and round effects. SE are clustered at country-round level." "The output variable is available for ESS rounds 1 (in 2002) and 7 (in 2014)."  "Effective sample: N= `N1' | Number of clusters= `chi1' | Outcome mean= `Meanm'.", size(small) span)
graph export "$Appendix/Figure_E_1b.png", replace



********** Figure E.2 **********
	
 grstyle init
	 grstyle set legend 12,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title 
    grstyle set graphsize 12cm 15cm
rdplot Noanswer running if  running>=-20 & running<=20 &  StrongFS==1,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) title("") ytitle("Missing Answer: % Foreigners") xtitle("Cohort relative to reform")   ylabel(#3))  note("")  yscale(range(-25  -5))  ylabel(-25(5)-5) 
graph export "$Appendix/Figure_E_2a.png", replace

rdplot Noanswer2 running if  running>=-20 & running<=20 &  StrongFS==1,  c(0) p(1) ci(95)  graph_options(graphregion(fcolor(white) lcolor(white)) ylab(,nogrid)  title("") ytitle("Missing Answer: % Unemployed") xtitle("Cohort relative to reform") )  note("") 
graph export "$Appendix/Figure_E_2b.png", replace






********** Table E.8 **********

est clear

matrix RDROBUST_matrix = J(6,4,0)
matrix rownames RDROBUST_matrix = "Reform" "SE" "p-value" "Bandwidth" "N." "Mean"
matrix colnames RDROBUST_matrix = "(1)" "(2)" "(3)" "(4)"
local i=0
			local i=`i'+1
			rdrobust Guess_foreign2 running if StrongFS==1,  covs(r1 r4 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 ) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'

			local i=`i'+1
			rdrobust Guess_unemployment2 running if StrongFS==1,  covs(r1 r4 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 ) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'

			local i=`i'+1
			rdrobust Noanswer running if StrongFS==1,  covs(r1 r4 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 ) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'

			local i=`i'+1
			rdrobust Noanswer2 running if StrongFS==1,  covs(r1 r4 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 ) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'

estout matrix(RDROBUST_matrix, fmt("5 3 4 0 0 2")) using "$Appendix\Table_E_8.tex", style(tex) replace starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001)






********** Table F.9 **********

preserve 

*do it only on waves where RD estimated (questions asked)
keep if essround==1 | essround==4 | essround==7 | essround==8


est clear

matrix RDROBUST_matrix = J(6,6,0)
matrix rownames RDROBUST_matrix = "Reform" "SE" "p-value" "Bandwidth" "N." "Mean"
matrix colnames RDROBUST_matrix = "(1)" "(2)" "(3)" "(4)" "(5)" "(6)"
local i=0

*Ideology
			local i=`i'+1
			quietly rdrobust Ideology running if StrongFS==1 , p(1) c(0) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'
*Interest
			local i=`i'+1
			quietly rdrobust Interest running if StrongFS==1 , p(1) c(0) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'
*Turnout 
			local i=`i'+1
			quietly rdrobust Turnout running if StrongFS==1 , p(1) c(0) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'
*Parliament 
			local i=`i'+1
			quietly rdrobust Parliament running if StrongFS==1 , p(1) c(0) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'
*Migrantsqualityoflife 
			local i=`i'+1
			quietly rdrobust Migrantsqualityoflife running if StrongFS==1 , p(1) c(0) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'
*Unemplazy 
			local i=`i'+1
			quietly rdrobust Unemplazy running if StrongFS==1 , p(1) c(0) 
			matrix RDROBUST_matrix[1,`i'] = e(tau_cl)
			matrix RDROBUST_matrix[2,`i'] = e(se_tau_cl)
			matrix RDROBUST_matrix[3,`i'] = e(pv_cl)
			matrix RDROBUST_matrix[4,`i'] = floor(e(h_l))
			matrix RDROBUST_matrix[5,`i'] = e(N_h_l) + e(N_h_r)
			sum eduyrs if r>=-floor(e(h_l)) & r<=floor(e(h_l))
			matrix RDROBUST_matrix[6,`i'] = `r(mean)'

estout matrix(RDROBUST_matrix, fmt("5 3 4 0 0 2")) using "$Appendix\Table_F_9.tex", style(tex) replace starlevels(+ 0.1 * 0.05 ** 0.01 *** 0.001)

restore 






